<!DOCTYPE html>
<html>
<head>
    {include file="public/header" /}
</head>
<body>
<div class="layuimini-container">
    <div class="layuimini-main">
        <table class="layui-hide" id="currentTableId" lay-filter="currentTableFilter"></table>
        <script type="text/html" id="currentTableBar">
            <a class="layui-btn layui-btn-xs" lay-event="check">查看聊天</a>
            <a class="layui-btn layui-btn-xs layui-btn-danger data-count-delete" lay-event="delete">删除</a>
        </script>

    </div>
</div>
{include file="public/footer" /}
<script type="text/html" id="statusTpl">
    {{#  if(d.status_mark == 1){ }}
    <span style="color: #28f51d;">进行中</span>
    {{# }else if(d.status_mark == 2){ }}
    <span style="color: #f59b28;">待开始</span>
    {{#  } else { }}
    <span style="color:#f42540;">已下架</span>
    {{#  } }}
</script>

<script>
    var opening;
    var confirmopen;
    layui.use(['form', 'table','laydate'], function () {
        var $ = layui.jquery,
            form = layui.form,
            table = layui.table,
            laydate=layui.laydate;
        $(function(){
             opening=layer.open({
                type: 1 ,
                title: "玩家搜索",
                area:['500px', '300px'],
                shade: 0.5,
                closeBtn: 0,
                maxmin: true,
                content: '<form class="layui-form " style="height:100%;display: flex;justify-content: center;align-items: center" onsubmit="return mySubmit()">\n' +
                '                    <div class="layui-form-item" style="width:100%;">\n' +
                '                        <div class="layui-inline" style="width:100%;">\n' +
                '                            <label class="layui-form-label">玩家搜索</label>\n' +
                '                            <div class="layui-input-inline" style="width:70%;">\n' +
                '                                <input type="text" id="search" autocomplete="off" class="layui-input" placeholder="请输入玩家名称，手机号，ID，回车键搜索">\n' +
                '                            </div>\n' +
                '                        </div>\n' +
                '                    </div>\n' +
                '                </form>'
            })
        });
        window.loadIngData=function(member_id){
            table.render({
                elem: '#currentTableId',
                url: '/admin/Imdata/chat_records?action=ajax&member_id='+member_id,
                method: 'post',
                parseData: function (res) { //res 即为原始返回的数据
                    return {
                        "code": res.code, //解析接口状态
                        "msg": res.msg, //解析提示文本
                        "count": res.data.total, //解析数据长度
                        "data": res.data.data, //解析数据列表
                    };
                },
                toolbar: '#toolbarDemo',
                defaultToolbar: ['filter', 'exports', 'print', {
                    title: '提示',
                    layEvent: 'LAYTABLE_TIPS',
                    icon: 'layui-icon-tips'
                }],
                cols: [[
                    {field: 'send_name', title: '玩家名称'},
                    {field: 'receipt_name', title: '对方玩家名称'},
                    {field: 'receipt_code', title: '对方玩家ID'},
                    {field: 'receipt_phone', title: '对方玩家手机号'},
                    {field: 'end_time', title: '最近聊天时间'},
                    {title: '操作', toolbar: '#currentTableBar', minWidth: 120}
                ]],
                limits: [10, 15, 20, 25, 50, 100],
                limit: 10,
                page: true,
                skin: 'line'
            });
        }


        // 监听搜索操作
        form.on('submit(data-search-btn)', function (data) {
            //执行搜索重载
            table.reload('currentTableId', {
                page: {
                    curr: 1
                }
                , where: {
                    searchParams: data.field
                }
            }, 'data');

            return false;
        });

        /**
         * toolbar监听事件
         */
        table.on('toolbar(currentTableFilter)', function (obj) {
            if (obj.event === 'add') {  // 监听添加操作
                var index = layer.open({
                    title: '添加活动',
                    type: 2,
                    shade: 0.2,
                    maxmin: true,
                    shadeClose: true,
                    area: ['100%', '100%'],
                    content: '/admin/Active/roulette_add',
                });
                $(window).on("resize", function () {
                    layer.full(index);
                });
            } else if (obj.event === 'delete') {  // 监听删除操作
                var checkStatus = table.checkStatus('currentTableId')
                    , data = checkStatus.data;
                layer.alert(JSON.stringify(data));
            } else if (obj.event === 'LAYTABLE_TIPS') {
                alert('自定义的,不用的话可以将该方法删除')
            }
        });

        //监听表格复选框选择
        table.on('checkbox(currentTableFilter)', function (obj) {
            console.log(obj)
        });

        table.on('tool(currentTableFilter)', function (obj) {
            var data = obj.data;
            if (obj.event === 'edit') {

                var index = layer.open({
                    title: '编辑活动',
                    type: 2,
                    shade: 0.2,
                    maxmin: true,
                    shadeClose: true,
                    area: ['100%', '100%'],
                    content: '/admin/Active/roulette_write?id='+data.id,
                });
                $(window).on("resize", function () {
                    layer.full(index);
                });
                return false;
            }else if(obj.event === 'check'){
                var index = layer.open({
                    title: '查看聊天记录',
                    type: 2,
                    shade: 0.2,
                    maxmin: true,
                    shadeClose: true,
                    area: ['100%', '100%'],
                    content: '/admin/Imdata/chat_records_list?id='+data.id,
                });
                $(window).on("resize", function () {
                    layer.full(index);
                });
                return false;
            } else if (obj.event === 'delete') {
                var index =  layer.confirm('确定要删除吗？', function (index) {
                    $.ajax({
                        url:'/admin/Imdata/chat_records_delete',
                        type:'post',
                        data:{
                            id:data.id
                        },
                        dataType:'json',
                        success:function(res){
                            obj.del();
                            layer.close(index);
                        }
                    })

                });
            }
        });

    });
    function mySubmit(){
        let search=$("#search").val();
        $.ajax({
            url:'/admin/Imdata/searchMember',
            type:'post',
            data:{
                search:search
            },
            dataType:'json',
            success:function(res){
                if(res.status){
                    confirmopen=layer.open({
                        type: 1 ,
                        title: "玩家搜索",
                        area:['1000px', '500px'],
                        shade: 0.5,
                        closeBtn: 0,
                        maxmin: true,
                        content:res.data
                    })
                    layer.close(opening);
                }else{
                    layer.msg("未查询到符合的数据");
                }
            }
        })

        return false;
    }
    function confirmMember(id)
    {
        loadIngData(id);
        layer.close(confirmopen);
    }
</script>

</body>
</html>